package com.zlm.reflect;

import java.lang.reflect.Constructor;
import java.util.Arrays;

/**
 * @author zlm
 * @date 2025/4/27
 */

public class TestConstructor {

    public static void main(String[] args) throws Exception {
        /*Class<?> aClass = Class.forName("com.zlm.reflect.Student");
        Constructor<?>[] constructors = aClass.getDeclaredConstructors();
        for (Constructor<?> constructor : constructors) {
            System.out.println(constructor.getName() + "------>" + Arrays.toString(constructor.getParameters()));
        }*/
        testGetConstructor();

    }

    public static void testGetConstructor() throws Exception {
        Class<?> aClass = Class.forName("com.zlm.reflect.Student");
        Constructor<?> constructor = aClass.getDeclaredConstructor(String.class,int.class);
        constructor.setAccessible(true);
        Student student = (Student) constructor.newInstance("zs",18);
        System.out.println(constructor.getName() + "------>" + constructor.getParameterCount());
        System.out.println(student);
    }



}
